package com.yoomiito.app.ui.my.income

import cn.droidlover.xdroidmvp.mvp.XPresent
import cn.droidlover.xdroidmvp.net.ApiException
import cn.droidlover.xdroidmvp.net.ApiSubscriber
import cn.droidlover.xdroidmvp.net.XApi
import com.yoomiito.app.Constant
import com.yoomiito.app.model.my.MyMonthOrderInfo
import com.yoomiito.app.net.YmApi
import com.yoomiito.app.utils.NetworkUtils
import com.yoomiito.app.utils.YMToast

class RevenueRelatedOrdersFmPresenter : XPresent<RevenueRelatedOrdersFragment?>() {

    fun getData(page: Int, month: Int) {
        YmApi.getYmService()
                .getMonthOrder_2(page, Constant.PAGE_SIZE)
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<MyMonthOrderInfo?>() {
                    override fun onSuccess(data: MyMonthOrderInfo?) {
                        v?.setMonthOrderData(data)
                    }

                    override fun onFail(error: ApiException) {
                        YMToast.showText("error")
                        v?.dismissLoading()
                    }
                })
    }

    fun getJDData(page: Int) {
        YmApi.getYmService()
                .jdMonthOrder(page, Constant.PAGE_SIZE)
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object : ApiSubscriber<MyMonthOrderInfo?>() {
                    override fun onSuccess(data: MyMonthOrderInfo?) {
                        v?.setMonthOrderData(data)
                    }

                    override fun onFail(error: ApiException) {
                        YMToast.showText("error")
                        v?.dismissLoading()
                    }
                })
    }
    
    fun getCreditCard(page:Int){
        YmApi.getYmService()
                .creditCardIncome(page,Constant.PAGE_SIZE)
                .compose(v?.bindToLifecycle())
                .compose(XApi.getApiTransformerData())
                .compose(XApi.getScheduler())
                .subscribe(object :ApiSubscriber<MyMonthOrderInfo>(){
                    override fun onSuccess(t: MyMonthOrderInfo?) {
                        v?.setMonthOrderData(t)
                    }

                    override fun onFail(error: ApiException?) {
                        YMToast.showText("error")
                        v?.dismissLoading()
                    }

                })
    }
}